import React, { useState } from 'react';
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from 'antd';
import type { FormProps } from 'antd';
import { useDispatch } from 'react-redux';
import { async_addshoplist, async_editshoplist } from '../../store/crmSlice';
import dayjs from 'dayjs';
type FieldType = {
  username?: string;
  password?: string;
  remember?: string;
};
const Addform: React.FC = (props) => {
    let dispatch=useDispatch()
     const [form] = Form.useForm();
     form.setFieldsValue(props.itemobj)
const onFinish: FortmProps<FieldType>['onFinish'] = (values) => {
  if(props.title=='添加'){
    let obj={
        "id": new Date().getTime(),
      ...values,
      "time":dayjs().format('YYYY-MM-DD HH:mm:ss') 
    }
    console.log(obj);
    dispatch(async_addshoplist(obj))
  }else{
    let obj={
        "id": props.itemobj.id,
      ...values,
      "time": dayjs().format('YYYY-MM-DD HH:mm:ss') 
    }
    dispatch(async_editshoplist(obj))
  }
    
    props.onCancel()
};

  return (
    <Form
      onFinish={onFinish}
      form={form}
      
    >
             <Form.Item label="参数主键" name='keyid'>
        <Input />
      </Form.Item>
      <Form.Item label="参数名称" name='name'>
        <Input />
      </Form.Item>
        <Form.Item label="参数键名" name='keyname'>
        <Input />
      </Form.Item>
        <Form.Item label="参数键值" name='key'>
        <Input />
      </Form.Item>
        <Form.Item label="系统内置" name='Collect'>
     <Radio.Group
    options={[
      { value: true, label: '是' },
      { value: false, label: '否' },

    ]}
  />
   
</Form.Item>
        <Form.Item label="备注" name='bz'>
        <Input />
      </Form.Item>
      <Form.Item label="Button">
        <Button type="primary" htmlType="submit">Button</Button>
      </Form.Item>
    </Form>
  );
};

export default Addform;
